package com.bootdo.lvyou.service.impl;

import com.bootdo.mall_part.dao.MallHousePlotDao;
import com.bootdo.mall_part.domain.MallHousePlot;
import com.bootdo.mall_part.service.MallHousePlotService;
import com.microsoft.schemas.office.visio.x2012.main.VisioDocumentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.bootdo.lvyou.dao.LvyouCityDao;
import com.bootdo.lvyou.domain.LvyouCity;
import com.bootdo.lvyou.service.LvyouCityService;
import org.springframework.transaction.annotation.Transactional;


@Service
public class LvyouCityServiceImpl implements LvyouCityService {
	@Autowired
	private LvyouCityDao lvyouCityDao;

	@Autowired
	private MallHousePlotDao mallHousePlotDao;
	
	@Override
	public LvyouCity get(Integer id){
		return lvyouCityDao.get(id);
	}
	
	@Override
	public List<LvyouCity> list(Map<String, Object> map){
		return lvyouCityDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return lvyouCityDao.count(map);
	}

	@Transactional
	@Override
	public int save(LvyouCity lvyouCity){

		int i = 0;
		if(lvyouCity.getId() != null) {
			return lvyouCityDao.update(lvyouCity);
		}else {
			i = lvyouCityDao.save(lvyouCity);
			if (lvyouCity.getGradeNumber() > 2) {
				MallHousePlot mallHousePlot = new MallHousePlot();
				mallHousePlot.setHouseFlag(1);
				mallHousePlot.setName(lvyouCity.getName() + "公共区");
				mallHousePlot.setAddress(lvyouCity.getName());
				mallHousePlot.setCityName(lvyouCity.getName());
				mallHousePlot.setAllAddress(lvyouCity.getName());
				mallHousePlot.setCityId(lvyouCity.getId().longValue());
				mallHousePlot.setCityOverIds("[" + lvyouCity.getId() + "]");
				mallHousePlot.setType(1);
				i = mallHousePlotDao.save(mallHousePlot);
			}

			return i;
		}		

	}
	
	@Override
	public int update(LvyouCity lvyouCity){
		return lvyouCityDao.update(lvyouCity);
	}
	
	@Override
	public int remove(Integer id){
		return lvyouCityDao.remove(id);
	}
	
	@Override
	public int batchRemove(Integer[] ids){
		return lvyouCityDao.batchRemove(ids);
	}

	@Override
	public List<LvyouCity> getByParent(Long cityId) {
		return lvyouCityDao.getByParent(cityId);
	}

	@Override
	public List<Long> getIdByParent(Long cityId) {
		return lvyouCityDao.getIdByParent(cityId);
	}

}
